package weightPolling

import (
	"fmt"
	"time"
)

func TestWeightPolicy() {
	weightTest()
	weightTest1()
}

func weightTest() {

	note := map[string]int{}

	s_time := time.Now().Unix()

	for i := 0; i < 16; i++ {
		s := GetDns()
		//fmt.Println(s)
		if note[s] != 0 {
			note[s]++
		} else {
			note[s] = 1
		}
	}

	e_time := time.Now().Unix()

	fmt.Println("total time: ", e_time-s_time)

	fmt.Println("--------------------------------------------------")

	for k, v := range note {
		fmt.Println(k, " ", v)
	}
}

func weightTest1() {
	wMap := make(map[int]int)
	wMap[0] = 6
	wMap[1] = 9
	wMap[2] = 3
	//wMap[3] = 6
	policy, err := NewWeightPolicy(wMap)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("policy:----->", policy)
	res := make(map[int]int)
	i := 0
	for {
		if i == 6 {
			break
		}
		i++
		w, index := policy.GetIndex()
		if res[index] != 0 {
			res[index]++
		} else {
			res[index] = 1
		}
		fmt.Println(w, index)
	}
	for k, v := range res {
		fmt.Println(k, " ", v)
	}
}
